package com.example.dao.impl;

import com.example.dao.MoneyDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;

/**
 * @Author: wyp
 * @Date: 2021/9/2 16:53
 */
@Repository
public class MoneyDaoImpl implements MoneyDao {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public void addMoney(Integer id, BigDecimal money) {
        String sql = "update money set money = money + ? where u_id = ?";
        jdbcTemplate.update(sql,money,id);
    }

    @Override
    public void reduceMoney(Integer id, BigDecimal money) {
        String sql = "update money set money = money - ? where u_id = ?";
        jdbcTemplate.update(sql,money,id);
    }
}
